/**************** 公共页面样式 ****************/

@import '../plugins/normalize.scss';
@import './module-styles/define-styles.scss';
@import '../plugins/short-tips.scss';
@import './module-styles/modal.scss';

/******** 公共页面样式变量 ********/
$header-height: 60px;
$footer-height: 50px;

/******** 全局样式自定义部分 ********/
* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  font: $base-font;
}

header.header {
  height: $header-height;
  background-color: $theme-color;
  color: $base-font-color;

  .center-block {
    height: 100%;
    @include center-block;
    display: flex;
    justify-content: space-between;
  }

  // Logo组
  .logo-group {
    height: 100%;

    a {
      height: 100%;
      text-decoration: none;
      font: bolder 1.88rem/1.88rem 'Microsoft YaHei', sans-serif;
      color: $base-font-color;
      display: flex;
      justify-content: flex-start;
      align-items: center;

      img {
        height: 80%;
        display: block;
      }

      .logo-text {
        margin-left: 8px;

        .main-title {
          font: bolder 1.54rem/1.64rem 'Microsoft YaHei', sans-serif;
        }

        .sub-title {
          text-align-last: justify;
          font: 13px/13px 'Microsoft YaHei', sans-serif;
        }
      }
    }
  }

  // 导航栏
  nav {
    ul {
      height: 100%;
      list-style: none;
      display: flex;
      margin: 0;

      li {
        height: 100%;

        a {
          height: 100%;
          padding: 0 18px;
          text-align: center;
          text-decoration: none;
          font-size: 1.4em;
          color: $base-font-color;
          display: flex;
          align-items: center;

          &.active {
            background-color: lighten($theme-color, 15%);
            color: #1a1b1c;
          }
        }
      }
    }
  }
}

main {
  height: calc(100% - ($header-height + $footer-height));
  overflow: hidden auto;
  padding-bottom: 32px;

  // 首页特殊处理
  &.index > article {
    display: block;

    h1 {
      text-align: center;
    }
  }

  // 非首页文章内容区域
  & > article {
    @include center-block(12px);
    display: flex;
    justify-content: flex-start;
    position: relative;

    // nav 导航栏
    nav {
      height: max-content;
      max-height: calc(100vh - 200px);
      flex-basis: 236px;
      margin-right: 24px;
      background-color: #fafbfe;
      border-radius: 24px;
      overflow: hidden auto;
      box-shadow: 0 4px 8px rgba(41, 42, 45, 0.15);
      position: sticky;
      top: 32px;

      .left-navlist {
        width: 100%;
        height: max-content;
        list-style: none;
        padding: 0;
        margin: 18px 0;

        li {
          padding: 0 18px;
          height: 40px;
          line-height: 40px;

          &:hover {
            background-color: #f1f2f5;
          }
          a {
            height: 100%;
            text-decoration: none;
            color: #5a5b5f;
            display: block;
          }

          &.active {
            background-color: $theme-color;

            a {
              font-weight: bold;
              color: #fff;
            }
          }
        }
      }
    }

    // 带注释说明的文本标签
    em.annotated {
      font: normal 1rem sans-serif;
      color: $problem-color;
      cursor: help;
      position: relative;
      border-bottom: 1px dashed $problem-color;

      &::after {
        content: attr(data-title);
        position: absolute;
        left: 50%;
        bottom: 100%;
        transform: translateX(-50%);
        width: max-content;
        max-width: 300px;
        padding: 6px 10px;
        border-radius: 4px;
        text-align: justify;
        text-indent: 0;
        font-size: 0.875rem;
        background-color: rgba(41, 42, 45, 0.9);
        color: #f6f7fa;
        visibility: hidden;
        z-index: 1;
      }

      &:hover::after {
        opacity: 1;
        visibility: visible;
      }
    }

    // 内容中的链接
    a {
      color: $base-link-color;

      &:hover {
        color: darken($base-link-color, 10%);
      }
    }

    // 页面章节导航
    .toggle-dynamic-anchor {
      position: fixed;
      z-index: 10;
      top: 74px;
      right: 12px;
      width: 40px;
      height: 40px;
      background: no-repeat url('../../images/icons/toggle-dynamic-anchor.svg')
        100% 100% / contain;
      cursor: pointer;
      opacity: 0.65;
      transition: all 0.15s ease-in-out;

      &:hover {
        opacity: 1;
      }

      // 动态锚点导航列表
      .dynamic-anchor-list {
        position: absolute;
        top: 0;
        right: 0;
        width: 240px;
        max-height: 460px;
        overflow-y: auto;
        background-color: #ffffff;
        border-radius: 12px;
        box-shadow: 0 8px 24px rgba(41, 42, 45, 0.2);
        list-style: none;
        padding: 12px 0;
        margin: 0;
        transform: scale(0);
        transform-origin: top right;
        opacity: 0;
        transition: transform 0.3s ease, opacity 0.3s ease;
        z-index: 1000;
        counter-reset: anchor-counter;
        user-select: none;

        &.show {
          transform: scale(1);
          opacity: 1;
        }

        li {
          padding: 10px 18px;
          font-size: 0.9rem;
          color: #3a3b3f;
          cursor: pointer;
          transition: background-color 0.2s ease, color 0.2s ease;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
          counter-increment: anchor-counter;

          &::before {
            content: counter(anchor-counter, simp-chinese-informal) '、';
            margin-right: 4px;
            font-weight: 500;
          }

          // 不显示序号的项（如章节练习）
          &.no-counter {
            counter-increment: none;

            &::before {
              content: '';
              margin-right: 0;
            }
          }

          &:hover {
            background-color: #f1f4ff;
            color: $theme-color;

            &::before {
              color: $theme-color;
            }
          }

          &:active {
            background-color: darken(#f1f4ff, 5%);
          }
        }
      }
    }

    // 文档内容区域
    .doc-content {
      flex: 1;
      color: $base-font-color;
      line-height: 1.64rem;
      counter-reset: h2-counter;

      h1 {
        text-align: center;
      }

      h2 {
        font-size: 1.36rem;
        counter-increment: h2-counter;
        padding-top: 1.4rem;
        margin-top: 1.4rem;
        border-top: 1px solid #cacbcf;

        &:first-of-type {
          margin-top: 0;
        }

        &::before {
          content: counter(h2-counter, simp-chinese-informal) '、';
        }
      }

      h3 {
        margin-top: 2rem;
        margin-bottom: 0;
      }

      // 章节练习
      .chapter-exercise {
        $exercise-bg-color: #482b0c;
        margin: 24px 0;
        padding: 12px 8px;
        background-color: $exercise-bg-color;
        border-radius: 24px;
        color: #f2ebe7;

        h2 {
          counter-increment: none;
          border: none;
          border-bottom: 1px solid lighten($exercise-bg-color, 10%);
          margin: 0;
          padding: 6px 12px 10px 12px;
          font: normal 1rem sans-serif;

          &::before {
            content: '';
          }
        }

        p {
          padding: 0 12px;
        }
      }

      p {
        text-align: justify;
        text-indent: 2em;

      }

      // 无缩进段落
      .no-indent {
        text-indent: 0;
        p {
          @extend .no-indent
        }
      }

      code:not([class^='language']) {
        padding: 2px 4px;
        border-radius: 4px;
        background-color: #f1f4ff;
        color: #232936;
      }

      ol,
      ul {
        padding-left: 3.2em;
        color: $subtext-color;

        li {
          margin: 0.4rem 0;

          & > ul,
          & > ol {
            padding-left: 1.2rem;
          }
        }
      }

      ol {
        list-style: none;
        counter-reset: List-Number;
        padding-left: 2rem;

        li {
          &::before {
            counter-increment: List-Number;
            content: counter(List-Number) '.\2000';
            font: bold 1rem 'Comic Sans MS', 'Lucida Sans Unicode', Arial,
              sans-serif;
          }
        }
      }

      // 图片内容
      div.img-content {
        p {
          img {
            max-width: 100%;
            display: block;
            cursor: pointer;
          }
        }
      }

      section {
        p {
          text-indent: 2em;
        }

        ol,
        ul {
          padding-left: 2em;
          color: #5c7895;
        }

        ol {
          list-style: none;
          counter-reset: List-Number;

          li {
            &::before {
              counter-increment: List-Number;
              content: counter(List-Number) '.\2000';
              font: bold 1rem 'Comic Sans MS', 'Lucida Sans Unicode', Arial,
                sans-serif;
            }
          }
        }
      }

      // 表格
      table {
        width: 100%;
        border-collapse: collapse;
        border: 1px solid #acacac;

        th,
        td {
          padding: 8px 12px;
          border: 1px solid #acacac;
        }

        thead {
          background-color: $theme-color;

          th {
            text-align: left;
            font: normal 0.937rem sans-serif;
            color: $dark-font-color;
            white-space: nowrap;
          }
        }

        tbody {
          tr {
            transition: all 0.15s;

            &:nth-child(even) {
              background-color: #fefcf3;
            }

            &:hover {
              background-color: #e9fff7;
            }

            td {
              color: $subtext-color;
            }
          }
        }
      }

      // 页面水平分割线
      hr {
        margin-top: 1.4rem;
      }
    }
  }
}

footer.footer {
  width: 100%;
  height: $footer-height;
  background-color: $footer-bgcolor;
  text-align: center;
  line-height: $footer-height;
  color: $gray-font-color;
  display: flex;
  justify-content: center;
  align-items: center;

  ul {
    width: max-content;
    height: 100%;
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    justify-content: center;
    align-items: center;

    li {
      width: max-content;
      height: 24px;
      padding: 0 12px;
      line-height: 24px;
      text-align: center;
      border-right: 1px solid darken($gray-font-color, 15%);
      font-size: 14px;

      &:last-child {
        border-right: none;
      }

      a {
        text-decoration: none;
        color: $gray-font-color;
      }
    }
  }
}

/* 代码块显示容器 */
pre:has(code) {
  padding: 4px 8px;
  background: #0d1117;
  border: 2px solid #475770;
  border-radius: 24px;

  code {
    line-height: 1.5rem;
  }
}

// 图片查看器
.image-viewer-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(8px);
  z-index: 9999;
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 0;
  transition: opacity 0.5s ease;
  cursor: pointer;
}

.image-viewer-container {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  max-width: 100%;
  max-height: 100%;
  transform: scale(0.5);
  opacity: 0;
  transition: transform 0.5s ease, opacity 0.5s ease;
}

.image-viewer-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.image-viewer-overlay.show {
  opacity: 1;
}

.image-viewer-container.show {
  transform: scale(1);
  opacity: 1;
}
